package orders

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"go.uber.org/zap"
	"order_srv/order"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderAddBargainLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewOrderAddBargainLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderAddBargainLogic {
	return &OrderAddBargainLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 砍价创建订单
func (l *OrderAddBargainLogic) OrderAddBargain(req *types.OrderAddBargainRequest) (resp *types.Response, err error) {
	bargain, err := l.svcCtx.OrderRpc.OrderAddBargain(l.ctx, &order.OrderAddBargainRequest{
		UserId:    uint32(req.UserId),
		BargainId: uint32(req.BargainId),
		AddressId: uint32(req.AddRessId),
		RealName:  req.RealName,
		UserPhone: req.UserPhone,
		PayType:   req.PayType,
	})
	if err != nil {
		pkg.Error("失败", zap.Error(err))
		return nil, err
	}
	return respons.Success(bargain), nil
}
